package com.cupk.controller;

import com.cupk.common.PageResult;
import com.cupk.common.Result;
import com.cupk.dto.AdminDto;
import com.cupk.dto.OrderDto;
import com.cupk.dto.ProviderDto;
import com.cupk.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * 名称OrderController
 * 描述
 *
 * @version 1.0
 * @author:XiongRuiKai
 * @datatime:2023-06-12 12:12
 */
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 有X条计划实施订单
     * @param orderId 父订单编号
     * @param startTime 起始时间
     * @param endTime 结束时间
     * @param page 第几页
     * @param pageSize 一页有多少数据
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult<OrderDto>> getOrderPage(
            @RequestParam(required = false) String orderId,
            @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime startTime,
            @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime endTime,
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int pageSize
    ){
        PageResult<OrderDto> OrderDtoPageResult = orderService.getQueryResultsWithPaging(orderId, startTime, endTime,page, pageSize);
        return Result.success(OrderDtoPageResult, "Success");
    }

    /**
     * 计划采购分页查询
     * @param orderId 父订单编号
     * @param startTime 起始时间
     * @param endTime 结束时间
     * @param page 第几页
     * @param pageSize 一页有多少数据
     * @return
     */
    @GetMapping("/plan/page")
    public Result<PageResult<OrderDto>> getOrderPlanPage(
            @RequestParam(required = false) String orderId,
            @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime startTime,
            @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime endTime,
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int pageSize
    ){
        PageResult<OrderDto> OrderDtoPagePlanResult = orderService.getQueryPlanResultsWithPaging(orderId, startTime, endTime,page, pageSize);
        return Result.success(OrderDtoPagePlanResult, "Success");
    }

    /**
     * 实施采购分页查询
     * @param orderId 父订单编号
     * @param startTime 起始时间
     * @param endTime 结束时间
     * @param page 第几页
     * @param pageSize 一页有多少数据
     * @return
     */
    @GetMapping("/execute/page")
    public Result<PageResult<OrderDto>> getOrderExecutePage(
            @RequestParam(required = false) String orderId,
            @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime startTime,
            @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime endTime,
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int pageSize
    ){
        PageResult<OrderDto> OrderDtoPageExecuteResult = orderService.getQueryExecuteResultsWithPaging(orderId, startTime, endTime,page, pageSize);
        return Result.success(OrderDtoPageExecuteResult, "Success");
    }

}
